package longrise.phone.com.bjjt_henan.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.longrise.LEAP.Base.Objects.EntityBean;

import longrise.phone.com.bjjt_henan.R;
import longrise.phone.com.bjjt_henan.Utils.CommontUtils;

/**
 * Created by Administrator on 2017-6-23.
 */

public class SnapshotAdapter extends BaseAdapter {

    private Context mContext;

    private EntityBean[] data;

    private View.OnClickListener listener;

    public SnapshotAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(EntityBean[] data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.length;
    }

    public void setListener(View.OnClickListener listener) {
        this.listener = listener;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_snapshot_item, null);
            holder.timeTV = (TextView) convertView.findViewById(R.id.snapshot_item_tv_time);
            holder.addressTV = (TextView) convertView.findViewById(R.id.snapshot_item_tv_address);
            holder.typeTV = (TextView) convertView.findViewById(R.id.snapshot_item_tv_type);
            holder.detailTV = (TextView) convertView.findViewById(R.id.snapshot_item_tv_detail);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        EntityBean bean = data[position];
        holder.timeTV.setText(bean.getString("createtime"));
        holder.addressTV.setText(bean.getString("accidentplace"));
        holder.typeTV.setText(CommontUtils.getPeccancyStr(bean.getString("accidenttype")));
        //拍摄详情
        holder.detailTV.setTag(bean);
        holder.detailTV.setOnClickListener(listener);

        return convertView;
    }

    private class ViewHolder {
        private TextView timeTV;
        private TextView addressTV;
        private TextView typeTV;
        private TextView detailTV;
    }
}
